import axios from "axios";
import { useUserStores } from "@/stores/index.js";

// const baseURL = "https://113.56.219.100:47672/api/";
const baseURL = "http://localhost:5242/api/";

let instance = axios.create({
  baseURL: baseURL,
  timeout: 10000,
  headers: {
    "Access-Control-Allow-Origin": "*",
  },
});

instance.interceptors.request.use(
  function (config) {
    // 在发送请求之前做些什么
    const userStores = useUserStores();
    config.headers.userCode = userStores.userCode;
    return config;
  },
  function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  }
);

export default instance;
export { baseURL };
